package code.snippet.bootstrap

import net.liftweb.http.Templates
import scala.xml.NodeSeq
import net.liftweb._
import http._
import util._
import Helpers._
import net.liftweb.sitemap.Loc


trait NavList extends DispatchSnippet {
  val template = Templates("templates-hidden" :: "bs" :: "_navlist" :: Nil)

  val items: Map[String, List[Pair[String, String]]] = Map(
    "第一组" -> List(
      "链接一" -> "/link1",
      "链接二" -> "/link2"
    )
  )

  val active = "/links"

  override def dispatch = {
    case _ => render _
  }

  def transformer = {
    ".segment ^*" #> (for ((header, links) <- items) yield
      ".nav-header *" #> header &
        ".nav-link" #> links.map { case (text, url) =>
          val trans = "a [href]" #> url & "a *" #> text
          if (url == active) trans & "* [class+]" #> "active" else trans
        })
  }

  def render(src: NodeSeq): NodeSeq = {
    template.map(transformer).getOrElse(NodeSeq.Empty)
  }


}
